﻿(function ($) {
    var _outboundPlasticContainerLogService = abp.services.app.outboundPlasticContainerLog,
        l = abp.localization.getSource('Boilerplate9'),
        _$modal = $('#OutboundPlasticContainerLogCreateModal'),
        _$form = _$modal.find('form'),
        _$table = $('#OutboundPlasticContainerLogsTable');

    var _$outboundPlasticContainerLogsTable = _$table.DataTable({
        paging: true,
        serverSide: true,
        listAction: {
            ajaxFunction: _outboundPlasticContainerLogService.getAll,
            inputFilter: function () {
                return $('#OutboundPlasticContainerLogsSearchForm').serializeFormToObject(true);
            }
        },
        buttons: [
            {
                name: 'refresh',
                text: '<i class="fas fa-redo-alt"></i>',
                action: () => _$outboundPlasticContainerLogsTable.draw(false)
            }
        ],
        responsive: {
            details: {
                type: 'column'
            }
        },
        columnDefs: [
            {
                targets: 0,
                className: 'control',
                defaultContent: '',
            },
            {
                targets: 1,
                data: 'deviceId',
                sortable: false
            },
            {
                targets: 2,
                data: 'labelCount',
                sortable: false
            },
            {
                targets: 3,
                data: 'creationTime',
                sortable: false
            }
        ]
    });

    abp.event.on('outboundPlasticContainerLog.edited', (data) => {
        _$outboundPlasticContainerLogsTable.ajax.reload();
    });

    _$modal.on('shown.bs.modal', () => {
        _$modal.find('input:not([type=hidden]):first').focus();
    }).on('hidden.bs.modal', () => {
        _$form.clearForm();
    });

    $('.btn-search').on('click', (e) => {
        _$outboundPlasticContainerLogsTable.ajax.reload();
    });

    $('.btn-clear').on('click', (e) => {
        $('input[name=Keyword]').val('');
        $('input[name=IsActive][value=""]').prop('checked', true);
        _$outboundPlasticContainerLogsTable.ajax.reload();
    });

    $('.txt-search').on('keypress', (e) => {
        if (e.which == 13) {
            _$outboundPlasticContainerLogsTable.ajax.reload();
            return false;
        }
    });
})(jQuery);
